<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCategoriesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('categories', function (Blueprint $table) {
            $table->id();
            $table->foreignId('article_id')->nullable()->constrained('articles')->onDelete('SET NULL');
            $table->unsignedBigInteger('pid')->default(0)->comment('父级目录');
            $table->foreignId('user_id')->nullable()->constrained('users')->onDelete('cascade');
            $table->string('path')->nullable()->index()->comment('多级目录路径');
            $table->string('title')->comment('栏目名称');
            $table->string('name')->comment('栏目名称英文标识');
            $table->string('preview')->nullable()->comment('缩略图');
            $table->string('keywords')->nullable()->comment('关键词');
            $table->string('description')->nullable()->comment('栏目描述');
            $table->text('content')->nullable()->comment('单文章内容');
            $table->string('url')->nullable()->comment('跳转链接');
            $table->boolean('homeshow')->default(false)->comment('是否首页显示');
            $table->boolean('recommended')->default(false)->comment('是否推荐');
            $table->boolean('top')->default(false)->comment('是否置顶');
            $table->tinyInteger('type')->default(1)->commit('1:普通栏目 2:封面栏目 3:单文章');
            $table->tinyInteger('structure')->default(1)->commit('1:列表圆形结构 2:十字文字结构 3:左右结构 4:大图CARD结构');
            $table->string('category_template')->default('category.blade.php')->comment('栏目内容页模板');
            $table->string('index_template')->default('index.blade.php')->comment('封面模板');
            $table->string('list_template')->default('list.blade.php')->comment('列表模板');
            $table->string('content_template')->default('content.blade.php')->comment('内容页模板');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('categories');
    }
}
